//
//  WCheckgoodsVC.m
//  ProjectforHDX
//
//  Created by motom on 16/8/24.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "WCheckgoodsVC.h"
#import "PlateModel.h"
#import "WCheckgoodsCell.h"
#import "WCheckgoodsBbottomV.h"
#import "MHScanViewController.h"
#import "CustomNavigationController.h"
#import "WCStroehouse.h"
#import "WCheckgoodsTopView.h"
#import "WCheckgoodsTitleView.h"
#import "PlateModel.h"

#define PLATESERIA  @"点击扫码"
#define PLATECODE  @"点击扫码"

@interface WCheckgoodsVC()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>


/*
 *扫描获取的条形码
 */
@property (nonatomic, copy) NSString *code;

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *platesArr;

@property (nonatomic, strong) NSMutableArray *platesDicArr;

@property (nonatomic, strong) WCheckgoodsTopView *topView;


@property (nonatomic, strong)WCStroehouse *house;

@end

@implementation WCheckgoodsVC


-(NSMutableArray *)platesDicArr
{
    if (!_platesDicArr) {
        _platesDicArr = [NSMutableArray array];
    }
    return _platesDicArr;
}

-(NSMutableArray *)platesArr
{
    if (!_platesArr) {
        _platesArr = [NSMutableArray array];
    }
    return _platesArr;
}

-(void)viewDidLoad
{
    [super viewDidLoad];
    [self  setupView];
//    [self loadData];
}

//-(void)loadData
//{
//    PlateModel *model = [[PlateModel alloc]init];
//    model.name = @"aa";
//    model.code = @"bb";
//    model.sn = @"cc";
//    model.containerNo = @"dd";
//    [self.platesArr addObject:model];
//    [self.tableView reloadData];
//    
//
//
//}

-(int)convertToInt:(NSString*)strtemp {
    
    int strlength = 0;
    char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
    for (int i=0 ; i<[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
        if (*p) {
            p++;
            strlength++;
        }
        else {
            p++;
        }
    }
    return (strlength+1)/2;
    
}


#pragma mark 底部按钮点击
-(void)setupView
{
    
    self.platesArr = [[NSMutableArray alloc]init];
    
    self.labnav.text = [UtilCheck language:@"main.orderInventory"];
    [self.labnav setFont:NavFontSize];
    [self.labnav setTextColor:[UIColor whiteColor]];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITableView *tableView = [[UITableView alloc]init];
    self.tableView = tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tableView setFrame:CGRectMake(0, 80, SCREEN_WIDTH, SCREEN_HEIGHT-200)];
    [self.view addSubview:tableView];
    
    WCheckgoodsTopView *headerView = [[WCheckgoodsTopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    self.topView = headerView;
    [headerView setPlateCount:self.platesArr.count];
    [self.view addSubview:headerView];

    WCheckgoodsTitleView *titleView = [[WCheckgoodsTitleView alloc]initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH, 40)];
    [self.view addSubview:titleView];
   
    
    WCheckgoodsBbottomV *bottomView = [[WCheckgoodsBbottomV alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-120, SCREEN_WIDTH, 60)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    __weak typeof(self) weakSelf = self;

    bottomView.Bottomblock = ^(long tag){
        
        switch (tag) {
            case 0: //盘点完成
            {
                if (self.platesArr.count == 0) {
                    [[BDHUD sharedManager]showWords:[UtilCheck language:@"HUD.pleaseCheckPlate"]];
                    break;
                }
                [self finishedCheck];
                
            }
                break;
            case 1: //扫描二维码
            {
                
                if (self.house.name == nil || self.house.name.length < 1) {
                    [Toolobject showTextWithMessage:[UtilCheck language:@"HUD.pleaseScnC"]];
                    break;
                }
                
          
                MHScanViewController *scanVC = [[MHScanViewController alloc]init];
                __weak typeof(self) weakSelf = self;
                scanVC.isdismiss = YES;
                scanVC.rebackData = ^(NSString *retStr){
                    
                    for (int i =0; i<self.platesArr.count; i++) {
                        PlateModel *tempModel = self.platesArr[i];
                        if ([tempModel.sn isEqualToString:retStr] ) {
                            [[BDHUD sharedManager]showWords:[UtilCheck language:@"HUD.hasScanPlate"]];
                            return ;
                        }
                    }
                    
                    [weakSelf getPartInfoWithQRCode:retStr];



                };
                CustomNavigationController *vc = [[CustomNavigationController alloc]initWithRootViewController:scanVC];
                [self presentViewController:vc animated:YES completion:^{
                    
                }];
                
            }
                break;
                
#pragma mark 点击一维码按钮添加一行
            case 2: //扫描一维码,添加一个cell
            {

                if (self.house.name == nil || self.house.name.length < 1) {
                    [Toolobject showTextWithMessage:[UtilCheck language:@"HUD.pleaseScnC"]];
                    return;
                }

                
                PlateModel *tempModel = [[PlateModel alloc]init];
                tempModel.sn = PLATESERIA;
                tempModel.code = PLATECODE;
                [self.platesArr addObject:[THMangerTool deepCopy:tempModel]];
                
                
                NSMutableDictionary *data = [[NSMutableDictionary alloc]init];
                [data setValue:self.house.name forKey:@"containerNo"];
                [data setValue:@"" forKey:@"code"];
                [data setValue:@"" forKey:@"sn"];
                [data setValue:@"" forKey:@"exception"];

                [self.platesDicArr addObject:[THMangerTool deepCopy: data]];
                [self.platesDicArr addObject:[THMangerTool deepCopy:tempModel]];

                [self.tableView reloadData];
                

            }
                break;
                
            case 3: //扫描库位
            {
                
                MHScanViewController *scanVC = [[MHScanViewController alloc]init];
                scanVC.isdismiss = YES;
                
                scanVC.rebackData = ^(NSString *retStr){
                    NSLog(@"%@",retStr);

                    [self getContainInfoWith:retStr];
                };
                CustomNavigationController *vc = [[CustomNavigationController alloc]initWithRootViewController:scanVC];
                [self presentViewController:vc animated:YES completion:^{
                    
                }];
                
                
                
            }
                break;

                
            default:
                break;
        }
    };
    
}




-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (self.platesArr.count < 1) {
        [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView top:60 title:[THMangerTool language:@"HUD.noCheck"] onClick:^{
        }];
        
    }else{
        [[BDHUD sharedManager] dismissHUD];
    }
}

#pragma -mark 点击事件  ---扫描一维码序列号

- (void)touchPlateSeria:(UITapGestureRecognizer *)recognizer{
    
    
    long index = recognizer.view.tag - 2000;
    PlateModel *tempModel = self.platesArr[index];
    
    if (tempModel.code == nil ) {
        [Toolobject showAlterwithMessage:[UtilCheck language:@"CachVC.ScanPlatCode"]];
        return;
    }
    
    
    MHScanViewController *scanVC = [[MHScanViewController alloc]init];
    __weak typeof(self) weakSelf = self;
    scanVC.isdismiss = YES;
    scanVC.rebackData = ^(NSString *retStr){
        
   
        tempModel.sn = retStr;

        
        [self getPartInfoWithBarCode:retStr andModel:tempModel andIndex:index];


    };
    CustomNavigationController *vc = [[CustomNavigationController alloc]initWithRootViewController:scanVC];
    [self presentViewController:vc animated:YES completion:^{
        
    }];

}

#pragma -mark 点击事件  ---扫描一维码板件号

- (void)touchPlateNo:(UITapGestureRecognizer *)recognizer{
    long index = recognizer.view.tag - 1000;
    
    
    MHScanViewController *scanVC = [[MHScanViewController alloc]init];
    __weak typeof(self) weakSelf = self;
    scanVC.isdismiss = YES;
    scanVC.rebackData = ^(NSString *retStr){
        
        PlateModel *tempModel = self.platesArr[index];
        tempModel.code = retStr;
        [weakSelf.platesArr replaceObjectAtIndex:index withObject:tempModel];
        
        NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithDictionary: weakSelf.platesDicArr[index]];
        [dict setValue:retStr forKey:@"code"];
        [weakSelf.platesDicArr replaceObjectAtIndex:index withObject:dict];
        [self.tableView reloadData];

        
    };
    CustomNavigationController *vc = [[CustomNavigationController alloc]initWithRootViewController:scanVC];
    [self presentViewController:vc animated:YES completion:^{
        
    }];
    
}

#pragma -mark 盘点完成
-(void)finishedCheck
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    NSDate *now = [NSDate date];
    NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
    fmt.dateFormat = @"YYYY-MM-dd HH:mm:ss";
    NSString *checkStartTime = [fmt stringFromDate:now];
    params[@"checkStartTime"] = checkStartTime;
    params[@"inventory"] = self.platesDicArr;
    
    [AFHttpTool postJsonDatawithUrl:@"/checkRecord" parameters:[params mutableCopy] success:^(id responseObject) {
        if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
            if([[responseObject objectForKey:@"data"] isKindOfClass:[NSDictionary class]]){
              [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                [self.navigationController popViewControllerAnimated:YES];
            }
            else{
                //返回数据出问题 弹出服务器返回信息
                if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                else{
                    [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
                }
            }
            
        }
        else{
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
            else{
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
            }
        }
    } fail:^(id responseObject, NSError *error) {
        [[BDHUD sharedManager] dismissHUD];
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
    }];
    
}



#pragma -mark 获取板件信息

- (void)getPartInfoWithQRCode:(NSString *) codeStr{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    params[@"containerCode"] = self.house.houseId;
    params[@"code"] = codeStr;
    
    [AFHttpTool postJsonDatawithUrl:@"/getPartInfo2" parameters:[params mutableCopy] success:^(id responseObject) {
        
        if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
            if([[responseObject objectForKey:@"data"] isKindOfClass:[NSDictionary class]]){
                NSMutableDictionary *data = [responseObject objectForKey:@"data"];
                data[@"containerNo"] = self.house.name;
                [data setValue:@"1" forKey:@"number"];
                [self.platesDicArr addObject:data];
                
                PlateModel *model = [[PlateModel alloc]init];
                model.containerNo = self.house.name;
                model.sn = [data objectForKey:@"sn"];
                model.code = [data objectForKey:@"code"];
                model.version = [data objectForKey:@"version"];
                model.name = [data objectForKey:@"name"];
                
                
                [self.platesArr addObject:[THMangerTool deepCopy:model]];
                [self.topView setPlateCount:self.platesArr.count];
                [self.tableView reloadData];
                
                if (self.platesArr.count < 1) {
                    [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView top:60 title:[THMangerTool language:@"HUD.noOrderData"] onClick:^{
                    }];
                    
                }else{
                    [[BDHUD sharedManager] dismissHUD:self.tableView];
                }
                
                
            }
            else{
                
                //返回数据出问题 弹出服务器返回信息
                if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                else{
                    [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
                }
            }
            
        }
        else{
            
            
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
            else{
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
            }
            
        }
    } fail:^(id responseObject, NSError *error) {
        
        
        
        [[BDHUD sharedManager] dismissHUD];
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
    }];

}


-(void)getPartInfoWithBarCode:(NSString *)code andModel:(PlateModel *)model andIndex:(long) index;
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
 
    params[@"containerCode"] = self.house.houseId;
    params[@"code"] = code;
    params[@"plateCode"] = model.code;
    params[@"plateSN"] = model.sn;


    [AFHttpTool postJsonDatawithUrl:@"/getPartInfo1" parameters:[params mutableCopy] success:^(id responseObject) {
   
        if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
            if([[responseObject objectForKey:@"data"] isKindOfClass:[NSDictionary class]]){
                NSMutableDictionary *data = [responseObject objectForKey:@"data"];
                data[@"containerNo"] = self.house.name;
                [self.platesDicArr  replaceObjectAtIndex:index withObject:data];
                
                PlateModel *model = [[PlateModel alloc]init];
                model.containerNo = self.house.name;
                model.sn = [data objectForKey:@"sn"];
                model.code = [data objectForKey:@"code"];
                model.version = [data objectForKey:@"version"];
                model.name = [data objectForKey:@"name"];
                model.number = @"1";
                
           
                [self.platesArr replaceObjectAtIndex:index withObject:[THMangerTool deepCopy: model]];
                [self.topView setPlateCount:self.platesArr.count];
                [self.tableView reloadData];
                
                if (self.platesArr.count < 1) {
                    [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView top:60 title:[THMangerTool language:@"HUD.noOrderData"] onClick:^{
                    }];
                    
                }else{
                    [[BDHUD sharedManager] dismissHUD:self.tableView];
                }

                
            }
            else{
                [Toolobject showAlterwithMessage:@"获取板件信息失败，请重新扫描序列号"];
       
                
                //返回数据出问题 弹出服务器返回信息
                if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                else{
                    [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
                }
            }
            
        }
        else{
            [Toolobject showAlterwithMessage:@"获取板件信息失败，请重新扫描序列号"];


            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
            else{
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
            }
            
        }
    } fail:^(id responseObject, NSError *error) {


        [Toolobject showAlterwithMessage:@"获取板件信息失败，请重新扫描序列号"];

        [[BDHUD sharedManager] dismissHUD];
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
    }];

}


#pragma -mark 从网络获取库位
-(void)getContainInfoWith:(NSString *)str
{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"code"] = str;
    [AFHttpTool postJsonDatawithUrl:@"/getContainerInfo" parameters:[params mutableCopy] success:^(id responseObject) {
        if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
            if([[responseObject objectForKey:@"data"] isKindOfClass:[NSDictionary class]]){
                NSDictionary *data=[responseObject objectForKey:@"data"];
                WCStroehouse *store = [[WCStroehouse alloc]init];
                [store setValuesForKeysWithDictionary:data];
                [self.topView setStroeInfo:store];
                self.house = store;
            }
            else{
                //返回数据出问题 弹出服务器返回信息
                if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                else{
                    [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
                }
            }
            
        }
        else{
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
            else{
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.noCheck"]];
            }
            
        }
    } fail:^(id responseObject, NSError *error) {
        [[BDHUD sharedManager] dismissHUD];
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
        
    }];

}



#pragma -mark tableView datasource delegate
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WCheckgoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WCheckgoodsCell"];
    if (!cell) {
        cell = [[WCheckgoodsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WCheckgoodsCell"
                ];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setPlateModle:self.platesArr[indexPath.row]];
    
    UITapGestureRecognizer *plateNoRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchPlateNo:)];
    cell.plateNo.tag = 1000 + indexPath.row ;
    plateNoRecognizer.view.tag = cell.plateNo.tag;
    [cell.plateNo addGestureRecognizer:plateNoRecognizer];
    cell.plateNo.userInteractionEnabled = YES;
    
    
    UITapGestureRecognizer *plateSeriaRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchPlateSeria:)];
    cell.plateSeria.tag = 2000 + indexPath.row ;
    plateSeriaRecognizer.view.tag = cell.plateSeria.tag;
    [cell.plateSeria addGestureRecognizer:plateSeriaRecognizer];
    cell.plateSeria.userInteractionEnabled = YES;
    
    cell.plateNum.tag = 3000 + indexPath.row;
    cell.plateNum.delegate = self;
    return cell;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.platesArr.count < 1) {
        [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView top:60 title:[THMangerTool language:@"HUD.noOrderData"] onClick:^{
        }];
        
    }else{
        [[BDHUD sharedManager] dismissHUD:self.tableView];
    }


    return self.platesArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"当前是第 %ld 个cell",(long)indexPath.row);
    WCheckgoodsCell *cell = [[WCheckgoodsCell alloc]init];
    [cell setPlateModle:self.platesArr[indexPath.row]];
    return cell.height;;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.platesArr removeObjectAtIndex:indexPath.row];
        [self.platesDicArr removeObjectAtIndex:indexPath.row];
        // Delete the row from the data source.
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

}

#pragma mark textfield 代理方法
-(void)textFieldDidEndEditing:(UITextField *)textField{
    long index = textField.tag - 3000;
    PlateModel *tempModel = self.platesArr[index];
    tempModel.number = textField.text;
    [self.platesArr replaceObjectAtIndex:index withObject: tempModel];
    
    
}


@end
